<template>
  <div id="app">
    <div class="container">
      <div class="close"><span class="iconfont iconicon-test"></span></div>
      <div class="logo"><span class="iconfont iconnew"></span></div>
      <div class="inputs">
        <hmInput placeholder="请输入昵称" v-model="user.nickname"></hmInput>
        <hmInput
          :reg="/^[1][3,4,5,7,8][0-9]{9}$/"
          placeholder="请输入手机号"
          v-model="user.username"
        ></hmInput>
        <hmInput placeholder="请输入密码" v-model="user.password"></hmInput>
      </div>
      <!-- <p class="tips">
        没有账号？
        <a href="#/register" class="">去注册</a>
      </p> -->
      <van-button icon="star-o" round type="danger" block @click="registerFn"
        >注册</van-button
      >
    </div>
  </div>
</template>

<script >
import hmInput from "../components/hmInput.vue";
import { register } from "../api/user.js";
export default {
  components: { hmInput },
  data() {
    return {
      user: {
        nickname: "",
        username: "",
        password: "",
      },
    };
  },
  methods: {
    registerFn() {
      register(this.user)
        .then((res) => {
          if (res.data.message == "注册失败,请检查参数") {
            // 注册失败
            this.$toast.fail(res.data.message);
          } else {
            // 注册成功
            this.$toast.fail(res.data.message);
            this.user.nickname = "";
            this.user.username = "";
            this.user.password = "";
            this.$router.push({
              path: "/login",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang='less' scoped>
.container {
  padding: 20px;
}
.close {
  span {
    font-size: (27 / 360) * 100vw;
  }
}
.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: (126 / 360) * 100vw;
    color: #d81e06;
  }
}
.inputs {
  input {
    margin-bottom: 20px;
  }
}
.tips {
  text-align: right;
  margin-bottom: 20px;
  a {
    color: #3385ff;
  }
}
</style>